package network

import (
	"io"
)

func IoCopy(left io.Reader, right io.Writer, onRead func(content []byte, readSecond int)) error {
	readSecond := 0
	for {
		readSecond++
		buf := make([]byte, 2024)
		n, err := left.Read(buf)
		if err != nil && err != io.EOF {
			break
		}
		onRead(buf[:n], readSecond)
		_, err = right.Write(buf[:n])
		if err != nil {
			return err
		}
	}
	return nil
}
